package com.newopenlab.hmc.util;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.List;

public class PSParserManager {
	
	public class HandFilter implements FileFilter
	{
	  private final String[] okFileExtensions = 
	    new String[] {"txt"};

	  public boolean accept(File file)
	  {
	    for (String extension : okFileExtensions)
	    {
	      if (file.getName().toLowerCase().endsWith(extension))
	      {
	        return true;
	      }
	    }
	    return false;
	  }
	}

	
	
	public PSParserManager(){}
	public List<BaseHand> parseDir(String dirS){
		List<BaseHand> list=new ArrayList<BaseHand>();
		BasicParser bp=new BasicParser();
		File dir=new File(dirS);
		File[] files = dir.listFiles(new HandFilter());
		List<BaseHand> aux=null;
		List<File> errors=new ArrayList<File>();
		for (File f : files){
			try{
		      bp.inputFile=f;
		      aux=bp.readBaseHands();
		      list.addAll(aux);
			}catch(Exception e){
				errors.add(f);
				System.out.println("ERRORE "+f.getName());
				e.printStackTrace();
				
			}
	    }
		for (File f : errors){
			System.out.println("ERRORE al file "+f.getName());
		}
		System.out.println("ERRORi nei file "+errors.size());
		return list;
	}
}
